package com.sskj.gocoin.v.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.p.activity.VerifyJuniorPresenter;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.base.BaseActivity;

import butterknife.BindView;

/**
 * ProjectName：期权
 * DESC: (类描述)初级实名认证
 * Created by hqf on 2018/10/19 10:23
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class VerifyJuniorActivity extends BaseActivity<VerifyJuniorPresenter> {
    @BindView(R2.id.toolBar)
    ToolBarLayout toolBar;
    @BindView(R2.id.real_name_verify)
    EditText realNameVerify;
    @BindView(R2.id.junnor_verify_spinner)
    Spinner junnorVerifySpinner;
    @BindView(R2.id.id_verify)
    EditText idVerify;
    @BindView(R2.id.tel_verify)
    EditText telVerify;  // 手机号地址
    @BindView(R2.id.address_verify)
    EditText addressVerify;  // 邮箱地址
    @BindView(R2.id.next_btn)
    Button nextBtn;
    @BindView(R2.id.high_verity)
    TextView highVerity;
    private int type = 1;  // 默认身份证

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_verify_junior;
    }

    @Override
    public VerifyJuniorPresenter getPresenter() {
        return new VerifyJuniorPresenter();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, VerifyJuniorActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onViewBinding() {
        super.onViewBinding();
        toolBar.setTitle(App.INSTANCE.getString(R.string.fabimineJavaVerifyJuniorActivity1));
        toolBar.setLeftButtonText(App.INSTANCE.getString(R.string.fabimineJavaVerifyJuniorActivity2));
        toolBar.setLeftButtonOnClickLinster(v -> finish());
//        if (CheckUtil.isEmail(MyAppLication.getMobile())) {
//            addressVerify.setText(MyAppLication.getMobile());
//            addressVerify.setEnabled(false);
//        } else {
//            telVerify.setText(MyAppLication.getMobile());
//            telVerify.setEnabled(false);
//        }
//        junnorVerifySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
//            @Override
//            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//                if (position == 0) {
//                    type = 1;
//                    idVerify.setHint(App.INSTANCE.getString(R.string.strVerifyJuniorActivity201));
//                } else {
//                    type = 2;
//                    idVerify.setHint(App.INSTANCE.getString(R.string.strVerifyJuniorActivity202));
//                }
//            }
//
//            @Override
//            public void onNothingSelected(AdapterView<?> parent) {
//
//            }
//        });

        ClickUtil.click(nextBtn, () -> {
            String realName = realNameVerify.getText().toString().trim();
            String idNum = idVerify.getText().toString().trim();
            if (TextUtils.isEmpty(realName)) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strVerifyJuniorActivity203));
                return;
            }
            if (TextUtils.isEmpty(idNum)) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.fabimineJavaVerifyJuniorActivity3));
                return;
            }
            if (idNum.length() != 18) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.strVerifyJuniorActivity205));
                return;
            }
//            if (!TextUtils.isEmpty(telNum)) {
//                if (!CheckUtil.isMobile(telNum)) {
//                    ToastUtil.showShort(App.INSTANCE.getString(R.string.strVerifyJuniorActivity207));
//                    return;
//                }
//            }
//            if (TextUtils.isEmpty(address)) {
//                ToastUtil.showShort(App.INSTANCE.getString(R.string.strVerifyJuniorActivity208));
//                return;
//            }
//            if (!CheckUtil.isEmail(address)) {
//                ToastUtil.showShort(App.INSTANCE.getString(R.string.strVerifyJuniorActivity209));
//                return;
//            }
            mPresenter.verifyJunior(realName, idNum);
        });
        ClickUtil.click(highVerity, () -> {
            VerifyGuideActivity.start(this);
        });
    }

    public void updateSuccess() {
        finish();
    }
}
